package routes

import (
	"com.wangzhumo.lottery/bootstrap"
	"com.wangzhumo.lottery/services"
	"com.wangzhumo.lottery/web/controllers"
	"github.com/kataras/iris/v12/_examples/mvc/login/web/middleware"
	"github.com/kataras/iris/v12/mvc"
)

func Configure(b *bootstrap.Bootstrapper) {
	// 初始化服务
	giftService := services.NewGiftServices()
	blackUserService := services.NewBlackUserService()
	blackIpService := services.NewBlackIpServices()
	codeService := services.NewCodeService()
	resultService := services.NewResultService()
	userDayService := services.NewUserDayService()

	// 路由
	// Index
	index := mvc.New(b.Party("/"))
	index.Register(userDayService, giftService,
		blackUserService, blackIpService, codeService, resultService)
	index.Handle(new(controllers.IndexController))

	// Admin
	admin := mvc.New(b.Party("/admin"))
	admin.Router.Use(middleware.BasicAuth)
	admin.Register(userDayService, giftService,
		blackUserService, blackIpService, codeService, resultService)
	admin.Handle(new(controllers.AdminController))

	// Admin Gift
	adminGift := admin.Party("/gift")
	adminGift.Register(giftService)
	adminGift.Handle(new(controllers.AdminGiftController))

	// 优惠券
	adminCode := admin.Party("/code")
	adminCode.Register(codeService)
	adminCode.Handle(new(controllers.AdminCodeController))

	// 中奖纪录
	adminResult := admin.Party("/result")
	adminResult.Register(resultService)
	adminResult.Handle(new(controllers.AdminResultController))

	// 黑名单 - ip
	adminBlackIp := admin.Party("/blackip")
	adminBlackIp.Register(blackIpService)
	adminBlackIp.Handle(new(controllers.AdminBlackIpController))


	// 黑名单 - user
	adminBlackUser := admin.Party("/user")
	adminBlackUser.Register(blackUserService)
	adminBlackUser.Handle(new(controllers.AdminUserController))

}
